<?php

    // +----------------------------------------------------------------------
    // | 后台记事本
    // +----------------------------------------------------------------------
    // | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
    // +----------------------------------------------------------------------
    // | Author: 微尘 <yicmf@qq.com>
    // +----------------------------------------------------------------------

    namespace addon\note\controller;

    use addon\note\model\Note as NoteModel;
    use app\event\ucenter\User as UserEvent;
    use yicmf\addon\controller\AdminController;

    class Note extends AdminController
    {

        public function save()
        {
            if ( $this->request->isPost() ) {


				$user->user = UserEvent::getLogin(app('http')->getName());
                $note = new NoteModel();
                $mynote = NoteModel::where('module', $this->request->post('module'))->where('user_id', $user['id'])->find();

                if ( $mynote ) {
                    $mynote->content = $this->request->post('content');
                    $data['data'] = $mynote->save();
                } else {
                    $note->content = $this->request->post('content');
                    $note->user_id = $user['id'];
                    $note->module = $this->request->post('module');
                    $data['data'] = $note->save();
                }
                $data['status'] = 0;
            } else {
                $data['status'] = 1;
                $data['message'] = '请求异常';
            }
            return json($data);
        }
    }
